package CalesRobot;

import battlecode.common.Direction;
import battlecode.common.GameActionException;
import battlecode.common.RobotController;
import battlecode.common.Upgrade;

public class BOTHeadquarters implements BOT 
{
	Boolean OUTPUT_DEBUG=true;
	
	public void RunBot(RobotController rc) throws GameActionException
	{
		if (rc.isActive()) 
		{
			// Spawn a soldier
			Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
			while(rc.senseMine(rc.getLocation().add(dir))!=null)
					dir.rotateLeft();
			if (rc.canMove(dir))
			{
				if(rc.getTeamPower()>100)//Make sure there is enough power to support this spawn
					rc.spawn(dir);
				else
				{
					ResearchNextUpgrade(rc);
				}
			}

		}
	}
	
	private void ResearchNextUpgrade(RobotController rc) throws GameActionException
	{
		Upgrade[] upgradeOrder={Upgrade.PICKAXE,Upgrade.FUSION,Upgrade.NUKE};
		for(Upgrade nextUpgrade :upgradeOrder)
		{
			if(!rc.hasUpgrade(nextUpgrade))
			{
				if(OUTPUT_DEBUG)System.out.println("Researching: "+nextUpgrade);
				rc.researchUpgrade(nextUpgrade);
				return;
			}
		}
		
	}
}
